import os

# 通过CMD命令关闭所有端口的进程
def killApiOut(port):
    # print("kill进程")
    killApi=os.popen("netstat -ano | findstr " + port.__str__())
    text1 = killApi.read()
    arr1=text1.split("\n")
    #print("进程个数为：",len(arr1)-1)
    sum = len(arr1)-1;
    res = "停止进程个数为:" + sum.__str__()
    for text1 in arr1:
        arr2=text1.split(" ")
        if len(arr2)>1:
            pid1=arr2[len(arr2)-1]
            os.system("taskkill /PID "+pid1+" /T /F")
    killApi.close()
    return res








    # killOut=os.popen("netstat -ano | findstr " + outport.__str__())
    # text0 = killOut.read()
    # arr4=text0.split("\n")
    # # print("进程个数为：",len(arr4)-1)
    # for text0 in arr4:
    #     arr3=text0.split(" ")
    #     if len(arr3)>1:
    #         pid=arr3[len(arr3)-1]
    #         os.system("taskkill /PID "+pid+" /T /F")
    # killOut.close()
    #
    # killStatus=os.popen("netstat -ano | findstr " + status.__str__())
    # text2 = killStatus.read()
    # arr5=text2.split("\n")
    # # print("进程个数为：",len(arr4)-1)
    # for text2 in arr5:
    #     arr6=text2.split(" ")
    #     if len(arr6)>1:
    #         pid=arr6[len(arr6)-1]
    #         os.system("taskkill /PID "+pid+" /T /F")
    # killStatus.close()
